package com.leetcode.partition14;

import java.util.HashMap;
import java.util.Map;

/**
 * @author rkc
 * @date 2022/9/9 9:31
 */
public class LC1386安排电影院座位 {

    private Map<Integer, Integer> map = new HashMap<>();

    public int maxNumberOfFamilies(int n, int[][] reservedSeats) {
        for (int[] seat : reservedSeats) {
            int x = seat[0], y = seat[1];
            if (y == 1 || y == 10) continue;
            map.put(x, map.getOrDefault(x, 0) | 1 << (y - 2));
        }
        int left = 0b11110000, mid = 0b00111100, right = 0b00001111;
        int ans = 2 * n - map.size() * 2;
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            int v = entry.getValue();
            if ((left & v) == 0 || (mid & v) == 0 || (right & v) == 0) {
                ans++;
            }
        }
        return ans;
    }
}
